package com.ey.service;

import com.ey.pojo.EducationInfo;
import com.ey.pojo.PersonalInfo;
import com.ey.util.AliyunOOSUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Corazono on 2018/10/12.
 */
@Service
public class WordService {
    public Map<String, Object> getWord(){
        Map<String, Object> data = new HashMap<String, Object>();

        // 简历模板需要的数据
        data.put("edutime1", "2017-9");
        data.put("edutime2", "2021-7");
        data.put("school", "厦门理工");
        data.put("major","软件工程");
        data.put("degree","本科");
        data.put("course","C语言程序设计、Java语言程序设计、软件工程、Oracle数据库、<w:br/>数据库原理与应用、高等数学、概率论、大学英语");

        // 自我评价列表
        List<String> comments = new ArrayList<>();
        comments.add("我感觉自己很tm强1");
        comments.add("我感觉自己很tm强2");
        comments.add("我感觉自己很tm强3");

        data.put("comments",comments);
        return data;
    }

    public Map<String, Object> getWord(EducationInfo education, PersonalInfo personal){
        Map<String, Object> data = new HashMap<String, Object>();

        // 简历模板需要的数据
        data.put("edutime1", education.getEdutime1());
        data.put("edutime2", education.getEdutime2());
        data.put("school", education.getSchool());
        data.put("major",education.getMajor());
        data.put("degree",education.getDegree());
        // 课程
        String course = education.getCourse();
        StringBuilder stringBuilder = null;
        // 如果课程字符长度大于26个，则换行
        if (course.length() > 26){
            stringBuilder = new StringBuilder(course);
            stringBuilder.insert(26,"<w:br/>");
        }
        data.put("course",stringBuilder);

        // 自我评价列表
        List<String> comments = personal.getComments();
        data.put("comments",comments);

        // 图片路径
        String photoPath = personal.getPhotoPath();
        // 图片转成base64编码
        String base64 = AliyunOOSUtil.requestUrlToBase64(photoPath);
        data.put("photo",base64);
        return data;
    }
}
